#include "serve.h"
#include "ui_serve.h"

serve::serve(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::serve)
{
    ui->setupUi(this);
    server=new QTcpServer;
    server->listen(QHostAddress::AnyIPv4,8000);//port 8000

    connect(server,&QTcpServer::newConnection,this,&serve::newClientHandler);
}

serve::~serve()
{
    delete ui;
}

void serve::newClientHandler()
{
    //建立TCP连接
    QTcpSocket *socket=server->nextPendingConnection();

    socket->peerAddress();//获取客户端的地址
    socket->peerPort();//获取客户端端口号

    ui->ipLineEdit->setText(socket->peerAddress().toString());
    ui->portLineEdit->setText(QString::number(socket->peerPort()));
}
